using UnityEngine;
using UnityEngine.EventSystems;

/// <summary>
/// 可挂载在 UI 元素（标题栏或拖动区域）上，实现用鼠标拖动整个窗口。
/// 需要一个 WindowController 引用（可以在 Inspector 指定或自动查找父物体）。
/// </summary>
public class User32Handle : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
{
    [Tooltip("可选，自动查找父对象的 WindowController")]
    public Intro Intro;

    void Reset()
    {
        if (Intro == null)
            Intro = GetComponentInParent<Intro>();
    }

    void Awake()
    {
        if (Intro == null)
            Intro = GetComponentInParent<Intro>();
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        if (Intro == null) return;
        if (eventData.button != PointerEventData.InputButton.Left) return;
        Intro.OnDragBegin();
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (Intro == null) return;
        Intro.OnDragging();
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (Intro == null) return;
        Intro.OnDragEnd();
    }
}